/**
 * fileName:  FruitStructureBean.java
 * author:  huaimi
 * Company:  Cloudland Studio
 * Createdate:  2014-6-7 下午2:22:22
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-7          huaimi            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.handler.support;

import java.util.ArrayList;
import java.util.List;

import org.cloudland.commercial.masterdata.bean.FruitEfficacy;
import org.cloudland.commercial.masterdata.bean.FruitStructure;
import org.cloudland.commercial.masterdata.bean.Stead;
import org.cloudland.commercial.masterdata.store.entity.EfficacyEntity;
import org.cloudland.commercial.masterdata.store.entity.FruitEfficacyEntity;
import org.cloudland.commercial.masterdata.store.entity.FruitStructureEntity;
import org.cloudland.commercial.masterdata.store.read.EfficacyReader;

/**
 * 水果结构的属性实现类，提供了对水果结构接口方法的实现
 * 
 * @ClassName FruitStructureBean
 * @author huaimi
 * @version %I%, %G%
 * @see
 * @since JDK1.6
 * 
 */
public class FruitStructureBean implements FruitStructure {

	/**
	 * fruitStructureEntity 水果结构领域实体
	 */
	private FruitStructureEntity fruitStructureEntity;
	
	/**
	 * efficacyReader 功效读取接口
	 */
	private EfficacyReader efficacyReader;
	
	/**
	 * 
	 * <pre>
	 * TODO 请充分描述该构造函数的作用，及其参数的作用。
	 * </pre>
	 * 
	 * @param fruitStructureEntity
	 * @param fruitStructureWriter
	 */
	public FruitStructureBean(EfficacyReader efficacyReader) {
		this(new FruitStructureEntity(), efficacyReader);
	}
	
	/**
	 * 
	 * <pre>
	 * TODO 请充分描述该构造函数的作用，及其参数的作用。
	 * </pre>
	 * 
	 * @param fruitStructureEntity
	 * @param fruitStructureWriter
	 */
	public FruitStructureBean(FruitStructureEntity fruitStructureEntity, EfficacyReader efficacyReader) {
		this.fruitStructureEntity = fruitStructureEntity;
		this.efficacyReader = efficacyReader;
	}
	
	/**
	 * @return
	 */
	public String getId() {
		return fruitStructureEntity.getSiteId();
	}

	/**
	 * @param siteName
	 */
	public void setName(String siteName) {
		fruitStructureEntity.setSiteName(siteName);
	}
	
	/**
	 * @return
	 */
	public String getName() {
		return fruitStructureEntity.getSiteName();
	}
	
	/**
	 * @param stead
	 */
	public void setStead(Stead stead) {
		Integer type = -1;
		switch (stead) {
			case ALL:
				type = Stead.ALL.code();
				break;
			case EDIBLE:
				type = Stead.EDIBLE.code();
				break;
			case HERB:
				type = Stead.HERB.code();
				break;
		}
		
		fruitStructureEntity.setSiteType(type);
	}
	
	/**
	 * @return
	 */
	public Stead getStead() {
		Stead returnStead = Stead.ALL;
		switch (fruitStructureEntity.getSiteType()) {
		case 0:
			returnStead =  Stead.ALL;
			break;
		case 1:
			returnStead =  Stead.EDIBLE;
			break;
		case 2:
			returnStead =  Stead.HERB;
			break;
		}
		return returnStead;
	}
	
	/**
	 * @param siteDescribe
	 */
	public void setDescribe(String siteDescribe) {
		fruitStructureEntity.setSiteDescribe(siteDescribe);
	}
	
	/**
	 * @return
	 */
	public String getDescribe() {
		return fruitStructureEntity.getSiteDescribe();
	}
	
	/**
	 * @param efficacy
	 */
	public void addEfficacy(FruitEfficacy efficacy) {
		fruitStructureEntity.addEfficacy(new FruitEfficacyEntity(efficacy.getId(), efficacy.getName(), efficacy.getDesc(), efficacy.getSort(), efficacy.getWeight()));
	}
	
	/**
	 * @param efficacyId
	 * @param weight
	 */
	public void addEfficacy(String efficacyId, Integer weight) {
		fruitStructureEntity.addEfficacy(new FruitEfficacyEntity("", "", efficacyId, -1, weight));
	}
	
	/**
	 * @return
	 */
	public List<FruitEfficacy> getEfficacyInfo() {
		
		List<FruitEfficacy> resultArr = new ArrayList<FruitEfficacy>(fruitStructureEntity.getEfficacy().size());
		
		EfficacyEntity efficacy = null;
		for (FruitEfficacyEntity entity : fruitStructureEntity.getEfficacy()) {
			efficacy = efficacyReader.findEfficacyById(entity.getEfficacyId());
			resultArr.add(new FruitEfficacyBean(entity, efficacy));
		}
		
		return resultArr;
	}
	

}
